<template>
	<section style="width:100%">
		<section>
			<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
				<el-form :inline="true">
					<el-form-item>
						<el-input v-model="userId" placeholder="玩家ID"></el-input>
					</el-form-item>
					<el-form-item label="变动开始时间">
						<el-date-picker
								v-model="cashStart"
								type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss"
								placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
					<el-form-item label="变动结束时间">
						<el-date-picker
								v-model="cashEnd"
								type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss"
								placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" v-on:click="getUsers(pageSize)">查询</el-button>
					</el-form-item>
				</el-form>
			</el-col>
			<!--列表-->
			<el-table :data="users" stripe highlight-current-row v-loading="listLoading" style="width: 100%;" :default-sort = "{prop: 'time', order: 'descending'}">
				<!--<el-table-column label="#" width="100">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="age" label="房间名称" width="120">-->
				<!--</el-table-column>-->
				<el-table-column prop="userId" label="玩家ID" width="120" sortable>
				</el-table-column>
				<el-table-column prop="record.gameId" label="游戏ID" width="200">
				</el-table-column>
				<el-table-column prop="record.amount" label="金币变化" width="140" sortable>
					<template slot-scope="scope">
						<label :class="{'red':scope.row.record.amount<0}">{{scope.row.record.amount | division}}</label>
					</template>
				</el-table-column>
				<el-table-column prop="record.operator" label="操作人" width="120">
				</el-table-column>
				<el-table-column prop="tradeTxt" label="金币类型" width="180">
				</el-table-column>
				<el-table-column prop="time" label="时间" min-width="200" sortable>
				</el-table-column>
				<!--<el-table-column label="明细" min-width="150">-->
					<!--<template scope="scope">-->
						<!--<el-button type="primary" size="small" @click="handleEdit">查询</el-button>-->
					<!--</template>-->
				<!--</el-table-column>-->
			</el-table>
			<!--工具条-->
			<el-col :span="24" class="toolbar">
				<el-pagination layout="sizes, total, prev, pager, next" :page-sizes="[15, 30, 50]" @current-change="handleCurrentChange" @size-change="handleSizeChange"  :page-size="pageSize" :total="total" style="float:right;">
				</el-pagination>
			</el-col>


			<!--<el-dialog title="查询" v-model="editVisible" :close-on-click-modal="false">-->
				<!--<el-table :data="users" stripe highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">-->
					<!--<el-table-column prop="age" label="时间" width="140">-->
					<!--</el-table-column>-->
					<!--<el-table-column prop="age" label="房间名称" width="120">-->
					<!--</el-table-column>-->
					<!--<el-table-column prop="name" label="金币变化" width="140">-->
					<!--</el-table-column>-->
					<!--<el-table-column prop="name" label="变化前金币" width="120">-->
					<!--</el-table-column>-->
					<!--<el-table-column prop="name" label="变化后金币" width="120">-->
					<!--</el-table-column>-->
					<!--<el-table-column prop="name" label="作弊率" width="100">-->
					<!--</el-table-column>-->
					<!--<el-table-column prop="age" label="作弊值" >-->
					<!--</el-table-column>-->
				<!--</el-table>-->
			<!--</el-dialog>-->
		</section>
	</section>
</template>

<script>
    import base64 from '../../api/base64'
    export default {
        data() {
            return {
                userId:'',
                cashStart:'',
                cashEnd:'',
                listLoading:false,
                users:[],
                total:0,
                page:1,
				pageSize:15
            }
        },
		created(){
            let agentId = sessionStorage.getItem('searchAgentId')
			if (agentId){
                this.userId = agentId
                sessionStorage.removeItem('searchAgentId')
			}
		},
        methods: {
            handleSizeChange(val) {
                this.pageSize = val
                this.getUsers(this.pageSize);
            },
            handleCurrentChange(val) {
                this.page = val;
                this.getUsers(this.pageSize);
            },
            //获取用户列表
            getUsers(page) {
                this.listLoading = true;
                let loginStart,loginEnd
                if (this.cashStart || this.cashEnd){
                    loginStart = Date.parse(new Date(this.cashStart))
                    loginEnd = Date.parse(new Date(this.cashEnd))
                }else{
                    loginStart = ''
                    loginEnd =''
                }
                this.$axios.get('/coin-records?userid='+this.userId+'&index='+this.page+'&size='+page+'&logatstart='+loginStart+'&logatend='+loginEnd,{},this.global().token).then((res)=>{
                    if (res.status == 200){
                        this.total = res.data.count
                        let userTable = res.data.data
                        let base = new base64.Base64()
                        userTable.forEach((val)=>{
                            if (val.nickname){
                                val.nickname = base.decode(val.nickname)
                            }
                            val.time = this.changeDate(val.logAt)
							if(val.tradeType>10){
                                val.tradeTxt = val.tradeType.toString().replace(11,'bug补偿(后台操作)').replace(12,'活动赠送(后台操作)').replace(13,'账号异常(后台操作)').replace(14,'其它(后台操作)').replace(15,'奖金池')
							}else{
                                val.tradeTxt = val.tradeType.toString().replace(0,'游戏结果').replace(1,'游戏结果').replace(2,'抽成').replace(3,'充值').replace(4,'赠送').replace(5,'提现').replace(6,'活动').replace(0,'未知')
                            }
                        })
                        this.users = userTable
                        this.listLoading = false
                    }else{
                        this.$message({message: res.data, type: 'error'});
                        this.listLoading = false
                    }
                })
            },
            editCash(id,state){
                this.$axios.patch('/user-withdrawl/'+id,{state:parseInt(state)},this.global().token).then((res)=>{
                    if (res.status == 200){
                        this.$message({message: '操作成功', type: 'success'});
                        this.getUsers(this.pageSize)
                    }else{
                        this.$message({message: res.data, type: 'error'});
                    }
                })
            }
        },
        mounted() {
            this.cashStart = this.Todate1(new Date(new Date()-24*60*60*1000),'yyyy-MM-dd HH:mm:ss')
            this.cashEnd =  this.Todate(new Date(new Date()),'yyyy-MM-dd HH:mm:ss')
            this.getUsers(this.pageSize);
        }
    }

</script>

<style scoped lang="stylus">
	.agent-path
		display flex
		padding-bottom 10px
		&>p
			padding-right 10px
		&>h3
			cursor pointer
</style>